主题
屏幕区域图像分类 - YoloClassify
函数简介
截取屏幕区域做图像分类(无 bbox)。
接口名称
YoloClassifyDLL 调用
long YoloClassify(long ola, int x1, int y1, int x2, int y2, long modelHandle, int topK);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。 |
| x1 | 整数型 | 屏幕区域左上角 x(绝对坐标),须 x2>x1 |
| y1 | 整数型 | 屏幕区域左上角 y |
| x2 | 整数型 | 屏幕区域右下角 x |
| y2 | 整数型 | 屏幕区域右下角 y |
| modelHandle | 长整数型 | 模型句柄,任务类型须与接口一致(Detect/Classify/…) |
| topK | 整数型 | 返回得分最高的前 K 个类别(非框数);Regions[].Rank=0 为 Top-1,建议 1~10 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
auto result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcsharp
using OLAPlug;
var ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5);
if (result.Success)
{
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorpython
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
# 模型加载失败,请检查路径与密码
pass
# 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5)
if result.Success:
# result.RegionCount 为检测框数量,result.Regions 含坐标与类别
# 完整 JSON 字段见 YOLO 推理结果说明文档
pass
# 失败时可查看 result.Errorjava
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcpp
var ola = com("OlaPlug.OlaSoft")
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5)
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorvbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
If modelHandle = 0 Then
' 模型加载失败,请检查路径与密码
End If
' 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5)
If result.Success Then
' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
' 完整 JSON 字段见 YOLO 推理结果说明文档
End If
' 失败时可查看 result.Errortext
.局部变量 ola, OLAPlug
ola.创建 ()
' 加载加密 YOLO 模型包
modelHandle = ola.YoloLoadModel(“models/yolov8n.olam“, “your_password“, 0)
.如果真 (modelHandle = 0)
' 模型加载失败,请检查路径与密码
.如果真结束
' 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5)
.如果真 (result.Success)
' result.RegionCount 为检测框数量,result.Regions 含坐标与类别
' 完整 JSON 字段见 YOLO 推理结果说明文档
.如果真结束
' 失败时可查看 result.Erroraardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 加载加密 YOLO 模型包
var modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
var result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errortext
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 加载加密 YOLO 模型包
长整数 modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0)
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
自动 result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5)
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Errorcpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 加载加密 YOLO 模型包
long modelHandle = ola.YoloLoadModel("models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
// 绑定窗口后截取全屏/客户区做 classify 推理,坐标 0,0,0,0 表示整个客户区
auto result = ola.YoloClassify(0, 0, 1920, 1080, modelHandle, 5);
if (result.Success) {
// result.RegionCount 为检测框数量,result.Regions 含坐标与类别
// 完整 JSON 字段见 YOLO 推理结果说明文档
}
// 失败时可查看 result.Error原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0) {
// 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloClassify(instance, 0, 0, 1920, 1080, modelHandle, 5);
if (resultJsonPtr != 0) {
char resultJson[512] = {0};
GetStringFromPtr(resultJsonPtr, resultJson, sizeof(resultJson));
FreeStringPtr(resultJsonPtr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
// 加载加密 YOLO 模型包
long modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0);
if (modelHandle == 0)
{
// 模型加载失败,请检查路径与密码
}
long resultJsonPtr = YoloClassify(instance, 0, 0, 1920, 1080, modelHandle, 5);
if (resultJsonPtr != 0) {
StringBuilder resultJson = new StringBuilder(GetStringSize(resultJsonPtr) + 1);
GetStringFromPtr(resultJsonPtr, resultJson, resultJson.Capacity);
FreeStringPtr(resultJsonPtr);
string resultJsonStr = resultJson.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
# 加载加密 YOLO 模型包
modelHandle = YoloLoadModel(instance, "models/yolov8n.olam", "your_password", 0)
if modelHandle == 0:
# 模型加载失败,请检查路径与密码
pass
resultJsonPtr = YoloClassify(instance, 0, 0, 1920, 1080, modelHandle, 5)
if resultJsonPtr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(resultJsonPtr, buf, 512)
ola.FreeStringPtr(resultJsonPtr)
resultJson = buf.value.decode("utf-8")返回值
长整数型:PascalCase JSON 推理结果字符串指针;失败时 Success 为 false。
注意事项
- 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
- 须为 Classify 模型;无 bbox,含 TopClassName/TopScore、Region.Rank。
- 推理入参(confidence、iou、topK、classes 等)详解见 推理输入参数说明。
- 推理结果 JSON 字段说明见 推理结果JSON说明。
- 返回的 JSON 字符串须调用 FreeStringPtr 释放。
本接口关键参数
| 参数 | 作用摘要 |
|---|---|
topK | 返回 Top-K 个分类结果(按 Score 排序),无 bbox |
Classify 无 confidence / iou。详见 推理输入参数说明。
